package com.dms.controller;

import com.dms.service.RepairManageService;
import com.dms.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @className: RepairManageController
 * @package: com.dms.controller
 * @description  后勤服务的报修模块controller
 * @author: sk
 */
@Controller
@RequestMapping("/repairManageController")
public class RepairManageController {

    @Autowired
    RepairManageService repairManageService;

    /**
     * 分页模糊查询报修列表
     * @param query
     * @param select
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getRepairListLimit")
    @ResponseBody
    public Msg getRepairListLimit(@RequestParam("query") String query, @RequestParam("select") Integer select, @RequestParam(value = "startData",required = false) String startData, @RequestParam(value = "endData",required = false) String endData, @RequestParam("pageNum") int pageNum,
                                  @RequestParam("pageSize") int pageSize){
        return Msg.success().add("repairList", repairManageService.getRepairListLimit(query, select, startData, endData, pageNum, pageSize))
                .add("total", repairManageService.getRepairTotal(query, select, startData, endData)).add("buildingList", repairManageService.getBuildingList());
    }

    /**
     * 设置报修解决时间
     * @param repairId
     * @param processingTime
     * @return
     */
    @PutMapping("/updateProcessingTime/{repairId}/{processingTime}")
    @ResponseBody
    public Msg updateProcessingTime(@PathVariable("repairId") Integer repairId,@PathVariable("processingTime") String processingTime){
        return repairManageService.updateProcessingTime(repairId, processingTime) > 0 ? Msg.success() : Msg.fail();
    }

    /**
     * 根据id删除报修信息
     * @param repairId
     * @return
     */
    @DeleteMapping("/deleteRepair/{repairId}")
    @ResponseBody
    public Msg deleteRepair(@PathVariable("repairId") Integer repairId){
        return repairManageService.deleteRepair(repairId) > 0 ? Msg.success() : Msg.fail();
    }

    /**
     * 物品报修申请
     * @return
     */
    @PostMapping("/addRepair")
    @ResponseBody
    public Msg addRepair(@RequestBody HashMap<String, String> map){
        return repairManageService.addRepair(map.get("dormitoryId"), map.get("repairTime"), map.get("repairReason")) > 0 ? Msg.success() : Msg.fail();
    }
}
